<template>
  <a-row :gutter="24">
    <a-col :span="24">
      <x-card v-if="hasPerm('sysSc:page')">
        <div slot="content" class="table-page-search-wrapper">
          <a-form layout="inline">
            <a-row :gutter="48">
              <a-col :md="6" :sm="18">
                <a-form-item label="学号">
                  <a-input v-model="queryParam.Id" allow-clear placeholder="请输入学号" />
                </a-form-item>
              </a-col>
              <a-col :md="6" :sm="18">
                <a-form-item label="姓名">
                  <a-input v-model="queryParam.StudentName" allow-clear placeholder="请输入姓名" />
                </a-form-item>
              </a-col>
              <a-col :md="6" :sm="18">
                <a-form-item label="课程名">
                  <a-select v-model="queryParam.Cname" allow-clear placeholder="请选择课程名">
                    <a-select-option v-for="(item) in courseList" :key="item.id" :value="item.cname" >{{ item.cname }}</a-select-option>
                  </a-select>
                </a-form-item>
              </a-col>
              <a-col :md="6" :sm="24" class="search-buttons">
                <a-button type="primary" @click="$refs.table.refresh(true)">查询</a-button>
                <a-button style="margin-left: 8px" @click="() => (queryParam = {})">重置</a-button>
              </a-col>
            </a-row>
          </a-form>
        </div>
      </x-card>
      <a-card :bordered="false">
        <s-table
          ref="table"
          :columns="columns"
          :data="loadData"
          :alert="options.alert"
          :rowKey="(record) => record.id"
          :rowSelection="options.rowSelection"
        >
        </s-table>
      </a-card>
    </a-col>
  </a-row>
</template>
<script>
import { STable, XCard, XDown } from '@/components'
import { Empty } from 'ant-design-vue'
import { getSysChoicePage } from '@/api/modular/system/choiceManage'
import { getSysCourseList } from '@/api/modular/system/courseManage'
export default {
  components: {
    XDown,
    XCard,
    STable
  },
  data() {
    return {
      // 查询参数
      queryParam: {},
      // 表头
      columns: [
        {
          title: '学号',
          dataIndex: 'id'
        },
        {
          title: '姓名',
          dataIndex: 'studentName'
        },
        {
          title: '课程名',
          dataIndex: 'cname'
        },
        {
          title: '学分',
          dataIndex: 'credit'
        }
      ],
      // 加载数据方法 必须为 Promise 对象
      loadData: (parameter) => {
        return getSysChoicePage(Object.assign(parameter, this.queryParam)).then((res) => {
          return res.data
        })
      },
      selectedRowKeys: [],
      selectedRows: [],
      defaultExpandedKeys: [],
      courseList: [],
      simpleImage: Empty.PRESENTED_IMAGE_SIMPLE,
      replaceFields: {
        key: 'id'
      },
      options: {
        alert: {
          show: true,
          clear: () => {
            this.selectedRowKeys = []
          }
        },
        rowSelection: {
          selectedRowKeys: this.selectedRowKeys,
          onChange: this.onSelectChange
        }
      }
    }
  },
  created() {
    this.getSysCourseList()
  },
  methods: {
    statusFilter (status) {
        // eslint-disable-next-line eqeqeq
        const values = this.courseList.filter(item => item.code === status)
        if (values.length > 0) {
          return values[0].value
        }
    },

    getSysCourseList(text) {
        getSysCourseList().then((res) => {
            this.courseList = res.data
        })
    },
    handleOk() {
      this.$refs.table.refresh()
    },
    onSelectChange(selectedRowKeys, selectedRows) {
      this.selectedRowKeys = selectedRowKeys
      this.selectedRows = selectedRows
    }
  }
}
</script>
<style lang="less">
.table-operator {
  margin-bottom: 18px;
}
button {
  margin-right: 8px;
}

</style>
